;
(function (call) {
    var strongcf = {
        mapId: "tjMap",
        selectedPro: [],
        playList: null,
        latestTime: null,
        isFirstGetTime: true,
        areaExent: {
            12: [114.94, 38.32, 119.80, 40.47], // 全市
            hhly: [108.71, 43.88, 123.66, 35.55] // 海河流域
        },
        router: {
            cfg: "/business/szyb/json/strongcf.json",
            procfg: '/monitor/getUserToSzybProCfg.do',
             //gridData: 'sjyb/queryGlfGridData',
			queryRadarByFENGL:"/largeModel/queryRadarByFENGL",
            gridData: "/zhfx/newRader/queryOneStationRadaData",
            newGridData: "/radar/newZhfx/newRader/queryOneStationRadaData",
            getLatestTime: 'sjyb/queryGlfGridDataLatestTime',
			getHBwtcpTimeUrl:"/zhfx/radar/getRadarNewestTime",
            getLatestRadarTime: 'zhfx/rader/qhRadarLatestTime',
            getNandaLatestTime: 'zhfx/rader/nanda/LatestTime',
            getLatestQsybTime: 'sjyb/queryTqsbLatestTime',
            queryMaxTimeForDYRH:'rhyb/queryMaxTimeForDYRH',
            getRawForDYRHFromTimeAndPeriod:'rhyb/getRawForDYRHFromTimeAndPeriod',
            getLatestPlfTime: 'zhfx/gridKGYB/queryPLF4DataLatestTime',
            getNandaSkData: 'zhfx/rader/nanda/sk',
            getNandaWtData: 'zhfx/rader/nanda/yb',
            gridRateData: 'zhfx/rader/qhRadar',
            gridQsybData: 'sjyb/queryTqsbDate',
            gridPlfData: 'zhfx/gridKGYB/queryPLF4Data',
			gridhbwtcpData:'zhfx/radar/getRadarGridAsByte',
            queryQpfQpeM4Data: 'sjyb/queryQpfQpeM4Data',
            queryNewestTimeOfRadarWT:'http://10.226.120.52:9010/weatherelecheck/queryCheckDataApi/queryNewestTimeOfRadarWT',
            queryRawOfRadarWT:'http://10.226.120.52:9010/weatherelecheck/queryCheckDataApi/queryRawOfRadarWT',
            queryRawWllTjyz:'raw/phy/readPhyToRaw',
            findPhyValue:'raw/phy/findPhyValue'
        },
        init: function () {
            var that = this;
            $.getJSON(that.router.cfg, function (cfg) {
				
                if (cfg) {
                    that.buildContainer(cfg);
                    that.bindEvt();
                }
            })
        },
        // 获取最新起报时间
        getLatestTime: function (elementId) {
            var that = this;
            that.isFirstGetTime = false;
            var param = {
                element: elementId
            };
            $.ajax({
                url: this.router.getLatestTime,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: param
            }).done(function (res) {
                if (res.isSuccess && res.data) {
                    
                    that.latestTime = res.data;
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }else{
                    that.latestTime = new Date(new Date($(".product-strongcf-datepicker #strongcfDate").IDatePicker().getVal()).getTime() - 1000*60*60)+"";
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })
        },
        getLatestTimeQPF10min:function(){
            var that = this;
            $.ajax({
                url: this.router.queryNewestTimeOfRadarWT,
                type: 'GET',
                dataType: 'json',
                async: false,
            }).done(function (res) {
                //res = res+"";
                if (res.qtime != "") {
                    that.latestTime = res.qtime.substring(0,4)+"-"+res.qtime.substring(4,6)+"-"+res.qtime.substring(6,8)+" "+res.qtime.substring(8,10)+":"+res.qtime.substring(10,12)+":00";
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })
        },
		//获取回波外推产品最新时间
		
		getHBwtcpTime:function(){
			var that = this;
            that.isFirstGetTime = false;
            var param = {
                eleType: "ECREF",
                queryTime: new Date().format("yyyy-MM-dd hh:mm:00")
            };
			$.ajax({
                url: this.router.getHBwtcpTimeUrl,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: param
            }).done(function (res) {
                if (res.isSuccess && res.data) {
                    that.latestTime = res.data;
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })
		},
        //获取清华雷达时间
        getLatestRadarTime: function () {
            var that = this;
            that.isFirstGetTime = false;
            var date = new Date(); 
            date.setMinutes(Math.floor(date.getMinutes()/6)*6);
            var newdate = new Date(date - 18*60*1000).format("yyyy-MM-dd hh:mm:00");
            that.latestTime = newdate;
            
            if($("#userInfo").data("isMatchuser")){
                 that.latestTime = "2022-07-26 11:36";
                
            }
            $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
            
            
            /**
            var stationNo = $(".product_station .active").attr("name");
            var param = {
                stationNo: stationNo
            };

            $.ajax({
                url: this.router.getLatestRadarTime,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: param
            }).done(function (res) {
                if (res.isSuccess && res.data) {
                    that.latestTime = res.data;
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })**/
        },
        //获取南大最新起报时间
        getNandaLatestTime: function (element) {
            var that = this;
            that.isFirstGetTime = false;
            var param = {
                element: element.ele_id,
                height: 0
            };
            if (element.ele_id === "CAPPIREF") {
                param.height = element.ele_name;
            }
            if (element.aging) {
                param.aging = element.aging;
            }
            $.ajax({
                url: this.router.getNandaLatestTime,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: param
            }).done(function (res) {
                if (res.isSuccess && res.data) {
                    that.latestTime = res.data;
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })
        },
        //获取潜势预报时间
        getLatestQsybTime: function (elementId, model, url) {
            var that = this;
            that.isFirstGetTime = false;
            var param = {
                element: elementId,
                model: model
            };
            $.ajax({
                url: url,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: param
            }).done(function (res) {
                if (res.isSuccess && res.data) {
                    that.latestTime = res.data;
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })
        },
        //获取多源融合降水外推最新时间
        getdyrhjswtTime: function () {
            var that = this;
            that.isFirstGetTime = false;
            var param = {
                bjtime: new Date().format("yyyy-MM-dd hh:mm:00")
            };
            $.ajax({
                url: this.router.queryMaxTimeForDYRH,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: param
            }).done(function (res) {
                if (res.code == 200 && res.data) {
                    that.latestTime = res.data;
                    $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(that.latestTime);
                }
            })
        },
        /**
         * 构建弹出框内容
         */
        buildContainer: function (data) {
            var that = this;
            if (!data) {
                return;
            }
            data.pro_type.forEach(function (item) {
                var $li = $(`<li id="${item.id}">${item.name}</li>`);
                $li.data('model', item);
                $li.off().click(function () {
                    if ($(this).hasClass("active")) {
                        return;
                    }
                    that.isFirstGetTime = true;
                    if (item.id == 'qsyb')
                        GIS.Extent.Set(that.mapId, {
                            xmin: that.areaExent[12][0],
                            xmax: that.areaExent[12][2],
                            ymax: that.areaExent[12][1],
                            ymin: that.areaExent[12][3]
                        });
                    else
                        GIS.Extent.Set(that.mapId, {
                            xmin: that.areaExent.hhly[0],
                            xmax: that.areaExent.hhly[2],
                            ymax: that.areaExent.hhly[1],
                            ymin: that.areaExent.hhly[3]
                        });
                    that.delAllLayer(); //切换模式后, 清空之前模式数据
                    $(this).addClass("active").siblings().removeClass("active");
                    $('.product-strongcf-datepicker').empty()
                        .append(`
						<div class="date-panel">
							<input class="DateAgent" id="strongcfDate" data-options="${item.dateOptions}" value="">
							<i class="btn-forward"></i>
							<i class="btn-backward"></i>
							<i class="btn-newest"></i>
						</div>`);
                    if(item.id == "wlltjyz"){
                        $('.product-strongcf-datepicker .date-panel').append(`<i class="btn-search"></i>`)
                    }
                    
                    $.IDate(".product-strongcf-datepicker .date-panel", {
                        query: function query(val) {
                            strongcf.buildLastTime(function () {
                                strongcf.getMultiGridData();
                            });
                        }
                    });
                    that.buildLastTime();
                    that.buildProContent(data.basic_pro[item.id] || []);
                    if(item.id != "wlltjyz"){
                        if(item.id == "qdlsb"){
                            $(".product-strongcf-list .product-model").find('li.default').trigger('click');
  
                            //$(".product-strongcf-list").find('li.default').trigger('click');
                        }else{
                            $(".product-strongcf-list").find('li.default').trigger('click');
                        }
                        
                    }else{
                        $(".product-strongcf-list .RAT_index").show();
                        $(".product-strongcf-list .RAT_index ul li:eq(0)").addClass("active");
                        $(".product-strongcf-list .product-model ul li:eq(0)").addClass("active");
                        $(".product-strongcf-list .product-item:eq(0) li.default").addClass("active");
                        $(".product-strongcf-list .SMG_index").hide();

                    }
                })
                $(".product-strongcf-tab ul").append($li);
               
            })
            //$(".product-strongcf-tab").show();
        },
        /**
         * 构建要素展示
         * data 要素列表
         */
        buildProContent: function (data) {
            var that = this;
            $(".product-strongcf-list").empty();
            data.forEach(function (item) {
                var $item = $('<div>').addClass('product-item');
                if (item.group_id == 'CNVC_index' || item.group_id == 'HAIL_index'|| item.group_id == 'RAT_index'|| item.group_id == 'SMG_index') {
                    $item = $('<div>').addClass('product-item ' + item.group_id + ' indexCfg').hide();
                } else if (item.group_id == 'model') {
                    $item = $('<div>').addClass('product-item ' + 'product-' + item.group_id + '');
                }
                var $title = $('<div>').addClass('product-title');
                $title.data('type', item.group_id);
                $title.html(item.group_name);

                if (!item.content) {
                    that.buildCustomPro($item);
                    $title.append('<i></i>');
                }
                $item.append($title);
                if (typeof item.station != "undefined") {
                    var $div = $("<div></div>");
                    $div.addClass("product_station");
                    $item.append($div);
                    var i = 0;
                    for (var key in item.station) {
                        var $span = $(`<span name=${item.station[key]} class=${i === 0 ? 'active' : ''}>${key}</span>`);
                        $div.append($span);
                        $span.unbind("click").bind("click", function () {
                            $div.find("span").removeClass("active");
                            $(this).addClass("active")
                        })
                        i++;
                    }
                }

                if (item.content) {
                    var $ul = $('<ul>');
                    item.content.forEach(function (pro) {
                        var $li = $(`<li><span>${pro.ele_name}</span></li>`);
                        if (pro.selected)
                            $li.addClass("default");
                        if (!pro.interval) {
                            pro.interval = item.interval;
                        }
                        $li.data('pro', pro);
                        if (pro.title)
                            $li.attr('title', pro.title);
                        if (pro.width)
                            $li.css("width", pro.width);
                        $ul.append($li);
                    })
                    $item.append($ul);
                }
                $(".product-strongcf-list").append($item);
            })
        },
        //点击显示pdf技术说明
        showTechPdf: function (id, path) {
            var that = this;
            if (CafeJS.ModalBoxExist(id)) {
                CafeJS.ModalBoxShow(id);
                return;
            }
            CafeJS.ModalBox({
                id: id,
                container: 'cafe-busis-container',
                title: "技术说明",
                width: 1300,
                height: 700,
                m_top: 70,
                m_right: 90,
                hasMask: true,
                hide: true,
                html: "<div id='" + id + "' style='width:100%;height:calc(100% - 10px)'></div>",
                showCall: function (obj) {
                    PDFObject.embed(path, "#" + id);
                },
                closed: function () { }
            });
        },
        buildCustomPro: function (obj) {
            $.getJSON(this.router.procfg, function (res) {
                if (res.success) {
                    var data = res.params.data;
                    var $ul = $('<ul>');
                    data.forEach(function (pro) {
                        var $li = $(`<li style="width:100%"><span>${pro.productName}</span></li>`);
                        pro.isCustom = true;
                        $li.data('pro', pro);
                        $li.attr('title', pro.productName);
                        $ul.append($li);
                    })
                    obj.append($ul);
                }
            })
        },
        // 初始化最近起报时间
        buildLastTime: function (call) {
            var interval = $(".product-strongcf-tab li.active").data("model").interval;
            var baseDate = $(".product-strongcf-datepicker #strongcfDate").val() + ":00";
            var newDate = new Date(baseDate);
            var liArr = [];
            for (var i = 0; i < 4; i++) {
                liArr.push(`<li class="${i == 0 ? 'active' : ''}" data-time="${newDate}">${newDate.format("ddhhmm")}</li>`);
                newDate.setHours(newDate.getHours() - interval);
            }
            $(".product-strongcf-datechange ul").empty().append(liArr.reverse().join(""));

            if (this.playList) {
                this.playList.init({
                    curDate: baseDate
                });
                if ($.isFunction(call))
                    call();
                if ($(".product-strongcf-list ul li.active").length > 0)
                    this.initQpTimeList();
            }
        },
        initQpTimeList:function() {
            var tabId = $('.product-strongcf-tab ul li.active').data('model').id;
            var eleId = $(".product-strongcf-list ul li.active").data('pro').ele_id;
            if(tabId == "qhwt"){
                if(eleId == 'QPF'){
                    if($('.cafe-tl-content i').length >= 2){
                        $(".cafe-tl-content i:nth-child(2)").addClass('active');
                        $(".cafe-tl-content i:nth-child(2)").attr('datetip', $(".cafe-tl-content i:nth-child(1)").attr('datetip'));
                    }
                    $(".cafe-tl-content i:nth-child(1)").remove();
                }
                if(eleId == 'QPE'){
                    var time = new Date($(".cafe-tl-content .cafe-tl-item.active").attr('title')).format('MM-dd hh:mm');
                    $(".cafe-layer-name").attr('title','卷积神经外推_QPE_' + time).text('卷积神经外推_QPE_' + time);
                }
            }
        },
        // 初始化播放列表
        initPlayList: function (pro) {
			
            var that = this;
			
            var startTime = pro.time;
			
            var layers = that.getModels(pro.ele);
            
			if(pro.ele.iswlltjyz){
				var model = $("#modal_strongcf .product-model li.active").data("pro")['model'];
				if("TJWRF" == model){
					pro.ele.interval = 60;
					pro.ele.maxHour = 72;
				}else{
					pro.ele.interval = 60*3;
					pro.ele.maxHour = 72;
				}
			}
			var interval = pro.ele.interval || 6;
            var maxHour = 1;
            if (pro.ele.maxHour) {
                maxHour = pro.ele.maxHour;
            }
			if(pro.bussitype == "strongcf" && !pro.ele.iswlltjyz && !pro.ele.ele_id !== "QPF1H" && !pro.ele.ele_id !== "QPF10M" && pro.ele.ele_id !== "QPF10min" && pro.ele.ele_id !== "QPF"&&!pro.ele.isqsyb){
				startTime = new Date(new Date(startTime).getTime()+1000*60*6).format("yyyy-MM-dd hh:mm:00")
			}
			if(pro.ele.ele_id === "QPF10M"|| pro.ele.isdyrhjswt){
				startTime = new Date(new Date(pro.time).getTime()+1000*60*10).format("yyyy-MM-dd hh:mm:00")
			}
			if(pro.ele.ele_id === "QPF1H" ){
				startTime = new Date(new Date(pro.time).getTime()+1000*60*60).format("yyyy-MM-dd hh:mm:00")
			}
			
            if (pro.ele.ele_id === "CAPPIREF" || pro.ele.ele_id === "TREC" || pro.ele.ele_id === "COMREF" || pro.ele.ele_id === "QPE1H" || pro.ele.ele_id === "QPE") {
                this.playList = CafeJS.Timeline3({
                    appendTo: "#a-m-timeline",
                    curDate: startTime,
                    type: 1,
                    pro: pro,
                    dateOpt: {
                        dateFmt: 'yyyy-MM-dd hh:mm',
                        timeInterval: interval,
                        customHm: []
                    },
                    timeInterval: interval,
                    layers: layers,
                    gisId: that.mapId,
                    call: function (pro) {
                        pro.forecastTime = that.playList.getCurTime();
                        CafeJS.layerManage.updateLayer(pro);

                        that.getModelGridData(pro);
                        that.initQpTimeList();
                    },
                    getPlayData: function (pro, timeArr) {
                        that.getModelGridData(pro, timeArr);
                    }
                });
            } else {
                this.playList = CafeJS.Timeline2({
                    appendTo: "#a-m-timeline",
                    curDate: startTime,
                    type: 1,
                    pro: pro,
                    maxHour: maxHour,
                    dateOpt: {
                        dateFmt: 'yyyy-MM-dd hh:mm',
                        timeInterval: interval,
                        customHm: []
                    },
                    timeInterval: interval,
                    layers: layers,
                    gisId: that.mapId,
                    call: function (pro) {
                        pro.forecastTime = that.playList.getCurTime();
                        CafeJS.layerManage.updateLayer(pro);

                        that.getModelGridData(pro);
                    },
                    getPlayData: function (pro, timeArr) {
                        that.getModelGridData(pro, timeArr);
                    }
                });
            }
            pro.forecastTime = that.playList.getCurTime();
            if (CafeJS.layerManage)
                CafeJS.layerManage.updateLayer(pro);
        },
        // 初始化图例
        initLegentpicker: function (ele, appendTo) {
            var that = this;
            var layers = that.getModels(ele);
            var layerIds = [];
            $.each(layers, function (i, m) {
                layerIds.push(m.id);
            });
            CafeJS.legentPicker = CafeJS.Legentpicker({
                appendTo: appendTo,
                gisId: that.mapId,
                layerId: layerIds,
                totalWidth: 400,
                h_legend: 15,
                seq: 'decrease',
                productId: ele.color_id,
                levels:ele.levels,
                isShowSlider: true
            });
        },
        // 获取选中的要素格点数据
        getMultiGridData: function () {
            var that = this;
            if (this.selectedPro.length === 0) return;
            this.selectedPro.forEach(function (pro) {
                var proInfo = that.getProInfo(pro);
                that.getModelGridData(proInfo);
            })
            var forecastTime = that.playList.getCurTime();
            var time = $(".product-strongcf-datepicker #strongcfDate").IDatePicker().getVal() + ":00";
            CafeJS.layerManage.updateLayerTime(time, 'strongcf', forecastTime);
        },
        getModelGridData: function (proInfo, timeArr) {
            var that = this;
			
            if (!proInfo) return;
            var pro = proInfo.ele;
            var element = pro.ele_id;
            var model = pro.model;
            var ncVal = '';
            if (pro.type == 'CNVC' || pro.type == 'HAIL') {
                element = pro.type;
                model = $(".product-model").find('li.active').data('pro').model;
                ncVal = pro.ele_id
            }
            var queryTime = that.playList.getCurTime();
            var qbTime = proInfo.time;
            var agings = [];
            var agingsNanda = [],
                agingNanda;
            if (timeArr) {
                var arr = timeArr.split(",");
                for (var i = 0; i < arr.length; i++) {
                    var time = new Date(new Date(arr[i]).getTime()).format("yyyy-MM-dd hh:mm:ss");
                    agings.push(time);
                }
            } else {
                agings.push(new Date(queryTime).format('yyyy-MM-dd hh:mm:ss'))
            }
            var route = that.router.gridData;
            var params = {};
            if(pro.isQp){
                route = that.router.queryQpfQpeM4Data;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                agingNanda = (new Date(queryTime).getTime() - new Date(qbTime).getTime()) / 1000 / 60;
                agingNanda = agingNanda < 100 ? '0'+agingNanda : agingNanda;
                params = {
                    qbTime: qbTime,
                    ybTime: agings.join(","),
                    aging: agingNanda,
                    type: proInfo.ele.ele_id.toLowerCase(),
                }
            }else if (pro.isStation) {
                var stationNo = $(".product_station .active").attr("name");
                route = that.router.gridRateData;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                params = {
                    qbTime: qbTime,
                    ybTimes: agings.join(","),
                    stationNo: stationNo
                }
            } else if (pro.isglfwt) {
                route = that.router.newGridData;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                params = {
                    queryTimes: new Date(qbTime).format('yyyyMMddhhmmss'),
                    interval:(((new Date(queryTime).getTime() - new Date(qbTime).getTime())/1000/60)/6)-1,
                    //ybTimes: agings.join(","),
                    //element: element  
                }
            } else if (pro.fldmx) {
                route = that.router.queryRadarByFENGL;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                params = {
                    queryTime: new Date(qbTime).format('yyyyMMddhhmmss'),
                    period:(new Date(queryTime).getTime() - new Date(qbTime).getTime())/(1000*60),
					modeType:"FengLei"
                    
                }
            } else if (pro.isqsyb) {
                route = that.router.gridQsybData;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                params = {
                    qbTime: qbTime,
                    ybTimes: agings.join(","),
                    element: element,
                    model: model,
                    ncVal: ncVal || 'VALUE'
                }
            } else if (pro.isplf) {
                route = that.router.gridPlfData;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                params = {
                    qbTime: qbTime,
                    ybTimes: agings.join(","),
                    element: element,
                    model: pro.model
                }

            } else if (pro.hbwtcp) {
				debugger
                route = that.router.gridhbwtcpData;
                qbTime = new Date(qbTime).format('yyyy-MM-dd hh:mm:ss');
                params = {
                    queryTime: qbTime,
                    aging: (new Date(queryTime).getTime() - new Date(qbTime).getTime())/(1000*60),
                    eleType: element
                }

            } else if (element === "QPF1H" || element === "QPF10M" || element === "COMREFFORCAST") {
                if (timeArr) {
                    timeArr.split(',').forEach(function (i) {
                        if (element === "QPF1H") {
                            agingNanda = (new Date(i).getTime() - new Date(qbTime).getTime()) / 1000 / 60 / 60;
                        } else {
                            agingNanda = (new Date(i).getTime() - new Date(qbTime).getTime()) / 1000 / 60;
                        }
                        agingsNanda.push(agingNanda);
                    })
                    agingsNanda = agingsNanda.join(',');
                } else {
                    if (element === "QPF1H") {
                        agingsNanda = (new Date(queryTime).getTime() - new Date(qbTime).getTime()) / 1000 / 60 / 60;
                    } else {
                        agingsNanda = (new Date(queryTime).getTime() - new Date(qbTime).getTime()) / 1000 / 60;
                    }
                }
                route = that.router.getNandaWtData;
                params = {
                    time: qbTime,
                    agings: agingsNanda,
                    element: element
                }
            }else if(pro.is10Min){
                route = that.router.queryRawOfRadarWT;
                params = {
                    foreTime: new Date(qbTime).format('yyyyMMddhhmmss'),
                    aging: (new Date(queryTime).getTime() - new Date(qbTime).getTime())/1000/60
                }
            }else if(pro.isdyrhjswt){
                route = that.router.getRawForDYRHFromTimeAndPeriod;
                let newAging = (new Date(queryTime).getTime() - new Date(qbTime).getTime())/1000/60;
                newAging = (newAging+"").padStart(3,0);
                params = {
                    bjtime: new Date(qbTime).format('yyyy-MM-dd hh:mm:ss'),
                    aging: newAging
                }
            }else if(pro.iswlltjyz){
                route = that.router.queryRawWllTjyz;
                if($(".product-strongcf-content .product-model li.active").length == 0){
                    $(".product-strongcf-content .product-model li:eq(0)").addClass("active");
                }
                params = {
                    date: new Date(qbTime).format('yyyyMMddhhmmss'),
                    model:$(".product-strongcf-content .product-model li.active").data("pro")["ele_id"],
                    element:pro.type,
                    phyIndex:pro.ele_id,
                    interval: (new Date(queryTime).getTime() - new Date(qbTime).getTime())/1000/60/60
                }
            } else {
                route = that.router.getNandaSkData;
                params = {
                    times: agings.join(","),
                    element: element
                }
                if (element === "CAPPIREF") {
                    params.height = pro.ele_name;
                }
            }
            if(pro.isdyrhjswt){
                $.ajax({
                    url: route,
                    type: 'POST',
                    dataType: 'json',
                    async: false,
                    data: params,
                }).done(function (res) {
					debugger
                    if (res.code == 200 && res.data!="") {
                        that.drawGridRawMap(that.Base64toArrayBuffer(res.data), pro);
                    }else{
                        alert("该时间点没有数据");
                    }
                })

                // CafeJS.ajax({
                //     url: route,
                //     params: params,
                //     type: "POST",
                //     success: function (e) {
                //         
                //         var arrayBuffer = e.response;
                //         if (arrayBuffer.byteLength === 0) {
                //             alert("该时间点没有数据");
                //             that.clearGridLayer(element);
                //             return;
                //         }
                //         that.drawGridRawMap(arrayBuffer, pro);
                //     }
                // })
            }else{
                CafeJS.ajax({
                    url: route,
                    params: params,
                    type: "GET",
                    success: function (e) {
						debugger
                        var arrayBuffer = e.response;
                        if (arrayBuffer.byteLength === 0) {
                            alert("该时间点没有数据");
                            that.clearGridLayer(element);
                            return;
                        }
                        that.drawGridRawMap(arrayBuffer, pro);
                    }
                })
            }
            
        },
        Base64toArrayBuffer(base64Data) {
            var base64 = base64Data.replace(/^data:image\/\w+;base64,/, "");
            const rawData = window.atob(base64);
            const outputArray = new Uint8Array(rawData.length);
            for (let i = 0; i < rawData.length; ++i) {
                outputArray[i] = rawData.charCodeAt(i);
            }
            return outputArray.buffer;
        },
        // 绘制格点色斑图
        drawGridRawMap: function (data, pro) {
            var typeArr = this.getModels(pro);

            var color_id = pro.color_id;
            var legentCfg = CafeJS.Legentconfig().cfg();
            var colorObj = legentCfg[color_id];
            if(pro.levels){
                colorObj.levels = pro.levels;
            }
            if (pro.models == 'isoline') {
                gridUtil.createIsoline(data, typeArr[0].id, colorObj.levels);
            } else {
                // 显示色斑和数值
                GIS.GridShow.showGrid(this.mapId, typeArr, data, {}, colorObj);
            }
            CafeJS.legentPicker.updateLegentRange(typeArr,this.mapId);
        },
        //获取要素样式
        getModels: function (pro) {
            var models = [];
            $.each(pro.models.split(","), function (i, m) {
                var layerId = "strongcf-layer-" + m + "-" + pro.ele_id;
                models.push({
                    type: m,
                    visible: true,
                    uv: false,
                    wd: false,
                    cacheConfig: 'noCache',
                    id: layerId
                });
            });
            return models;
        },
        // 增加产品图层
        addLayerManage: function (proInfo) {
            var that = this;
            if (CafeJS.layerManage) {
                CafeJS.layerManage.addLayer(proInfo);
            } else {
                CafeJS.layerManage = CafeJS.LayerManage({
                    appendTo: "#c-b-layermanage",
                    mapId: that.mapId,
                    proInfo: proInfo,
                    call: function (pro) {
                        CafeJS[pro.bussitype].initPlayList(pro);
                    },
                    close: function (pro) {
                        CafeJS[pro.bussitype].delLayer(pro);
                    }
                })
            }
            that.initQpTimeList();
            if (proInfo.ele.models == 'isoline') return;
            if (proInfo.isGrid && !proInfo.ele.frames) {
                that.initLegentpicker(proInfo.ele, '.cafe-layer-item.active');
            }
        },
        // 删除图层后取消要素选择
        delLayer: function (pro) {
            var eleid = pro.ele.ele_id;
            if (pro.isGrid) {
                $(".product-strongcf-list li.active").each(function () {
                    if ($(this).data('pro').ele_id == eleid) {
                        $(this).click();
                        return false;
                    }
                })

                $(".product-strongcf-list td.active").each(function () {
                    if ($(this).data('pro').ele_id == eleid) {
                        $(this).click();
                        return false;
                    }
                })
            }
        },
        // 删除该模式所有的要素数据
        delAllLayer: function () {
            $(".product-strongcf-list li.active,.product-strongcf-list td.active").each(function () {
                $(this).click();
            })
        },
        // 移除当前要素的图层
        removeLayer: function (ele) {
            var proInfo = this.getProInfo(ele);
            CafeJS.layerManage.removeLayer(proInfo);
        },
        getProInfo: function (ele) {
            var height = ele.height != undefined ? ele.height : '';
            var name = $('.product-strongcf-tab li.active').data('model').name;
            name += '_' + height + ele.ele_name;
            var time = $(".product-strongcf-datepicker #strongcfDate").IDatePicker().getVal() + ':00';
            var proInfo = {
                name: name,
                time: time,
                bussitype: 'strongcf',
                ele: ele,
                isGrid: true,
                isSK: false
            }
            return proInfo;
        },
        // 清除格点图层
        clearGridLayer: function (ele_id) {
            var layerIds = [];
            if (!ele_id) return;
            GLMap.layerIds.forEach(function (layerId) {
                if (layerId.indexOf('strongcf-layer') != -1 && layerId.indexOf(ele_id) != -1) {
                    layerIds.push(layerId);
                }
            })
            GIS.LayerControll.deleteLayer(this.mapId, layerIds);
        },
        findPhyValue:function(pro,fun){
            var that = this;
            if("ZSSUM" == pro.ele_id){
                fun();
                return;
            }
            
            $.ajax({
                url: that.router.findPhyValue,
                type: 'GET',
                dataType: 'json',
                async: false,
                data: {
                    date:new Date($("#strongcfDate").val()+":00:00").format('yyyyMMddhhmmss'),
                    element:pro.type,
                    phyIndex:pro.ele_id,
                    model:$(".product-strongcf-list .product-model li.active").data("pro").ele_id
                }
            }).done(function (res) {
                if (res.code == 0) {
                    pro.color_id = res.data.relation == "0"?"WLLYZ_LT":"WLLYZ_GT";
                    pro.levels = [Number(res.data.value)];
                   fun();
                }else{
                    alert("查询阈值失败");
                }
            })
        },
        /**
         * 绑定事件操作
         */
        bindEvt: function () {
            var that = this;
            // 要素点击事件
            $(".product-strongcf-list").off('click').on('click', 'li', function () {
                
                var pro = $(this).data('pro');
                if (pro.pdf_path) {
                    that.showTechPdf(pro.ele_id, pro.pdf_path);
                    return false;
                }
                if ($(this).hasClass("active")) {
                    $(this).removeClass("active");
					if(pro.iswlltjyz && pro.model){
						return;
					}
                    that.selectedPro = that.selectedPro.filter(item => item.ele_id != pro.ele_id);

                    that.clearGridLayer(pro.ele_id);
                    that.removeLayer(pro);
                } else {

					if(!pro.iswlltjyz){
                        $(this).siblings('li.active').click(); // 清除之前选中的
                        $(this).addClass("active");
						$(this).closest('.product-model').siblings().find('li.active').click();
					}else{
                        $(this).addClass("active").siblings('li.active').removeClass("active");
                    }
                    if(pro.iswlltjyz && (pro.model || pro.isIndex)){
						return;
					}
                    if (pro.isStation) {
                        if (that.isFirstGetTime) {
                            that.getLatestRadarTime();
                        }
                    } else if (pro.isglfwt) {
                        if (that.isFirstGetTime) {
                            that.getLatestTime(pro.ele_id);
                        }
                    } else if (pro.isdyrhjswt) {
                        
                        if (that.isFirstGetTime) {
                            that.getdyrhjswtTime(pro.ele_id);
                        }
                    } else if (pro.isqsyb) {
                        if (!pro.type) {
                            $(".indexCfg").hide();
                            $('.' + pro.ele_id + "_index").find('li').each(function (i, item) {
                                $(item).data('pro').maxHour = pro.maxHour;
                                $(item).data('pro').interval = pro.interval;
                            });
                            $('.' + pro.ele_id + "_index").show();
                            if (that.isFirstGetTime) {
                                that.getLatestQsybTime(pro.ele_id, pro.model, that.router.getLatestQsybTime);
                            }
                           
                            $('.' + pro.ele_id + "_index").find('li:eq(0)').removeClass("active").trigger('click');
                            return;
                        }
                    }  else if (pro.iswlltjyz) {
                        if (!pro.type) {
                            $(".indexCfg").hide();
                            $('.' + pro.ele_id + "_index").find('li').each(function (i, item) {
                                $(item).data('pro').maxHour = pro.maxHour;
                                $(item).data('pro').interval = pro.interval;
                            });
                            $('.' + pro.ele_id + "_index").show();
                            return;
                            if(pro.iselement){
                                return;
                            }
                            if (that.isFirstGetTime) {
                                that.getLatestQsybTime(pro.ele_id, pro.model, that.router.getLatestQsybTime);
                            }
                        }
                    } else if (pro.isplf) {
                        if (that.isFirstGetTime) {
                            that.getLatestQsybTime(pro.ele_id, pro.model, that.router.getLatestPlfTime);
                        }
                    } else if (pro.hbwtcp) {
                        if (that.isFirstGetTime) {
                            that.getHBwtcpTime(pro.ele_id, pro.model, that.router.getLatestPlfTime);
                        }
                    }else if(pro.is10Min){
                        //that.getLatestTimeQPF10min();
                    } else {
                        if (that.isFirstGetTime) {
                            that.getNandaLatestTime(pro);
                        }
                    }

                    that.selectedPro.push(pro);

                    var proInfo = that.getProInfo(pro);
                    // 增加产品图层
                    that.addLayerManage(proInfo);

                    that.getModelGridData(proInfo);
                }
            })
            // 最近起报时间
            $(".product-strongcf-datechange").delegate('li', 'click', function () {
                $(this).addClass("active").siblings().removeClass("active");
                var time = $(this).data('time');
                $(".product-strongcf-datepicker #strongcfDate").IDatePicker().setVal(time);
                that.playList.init({
                    curDate: time
                });

                that.getMultiGridData();
            })
            $('.product-strongcf-datepicker').off('click').on('click', '.btn-forward', function (e) { // 日期向前
                e.stopPropagation();
                $(".product-strongcf-datepicker #strongcfDate").IDatePicker().toForward();
                that.buildLastTime(function () {
                    that.getMultiGridData();
                });
            }).on('click', '.btn-backward', function (e) { // 日期向后
                e.stopPropagation();
                $(".product-strongcf-datepicker #strongcfDate").IDatePicker().toBackward();
                that.buildLastTime(function () {
                    that.getMultiGridData();
                });
            }).on('click', ".btn-newest", function (e) { // 最新
                e.stopPropagation();
                $(".product-strongcf-datepicker #strongcfDate").IDatePicker().toNewest();
                that.buildLastTime(function () {
                    that.getMultiGridData();
                });
            }).on('click', ".btn-search", function (e) { // 查询
                e.stopPropagation();
                var proELem = $(".product-item.indexCfg:visible .active");
                if(proELem.length == 0){
                    $(".product-item.indexCfg:visible ul li:eq(0)").addClass("active");
                }
                proELem = $(".product-item.indexCfg:visible .active");

                $(".product-item.indexCfg:not(:visible) li.active").removeClass("active");
                if(that.selectedPro.length>0){
                    that.selectedPro.map(item=>{
                        that.removeLayer(item);
                        that.clearGridLayer(item.ele_id);
                    })

                }
                var pro = $(".product-item.indexCfg:visible ul li.active").data("pro");
                that.findPhyValue(pro,function(){
                    //that.removeLayer(pro);
                    that.selectedPro = [];
                    that.selectedPro.push(pro);
                    var proInfo = that.getProInfo(pro);
                    // 增加产品图层

                    that.addLayerManage(proInfo);
                    that.getMultiGridData();
                })

            });
            //$(".product-strongcf-tab li").first().click();
        }
    }
    if (typeof call === 'function') {
        CafeJS.strongcf = strongcf;
        call(strongcf);
    }
    window.strongcf = strongcf;
})(function (strongcf) {
    CafeJS.models(['ajax', 'legentconfig', 'legentpicker', 'timeLine2', 'timeLine3'], function () {
        strongcf.init();
    });
});
